package com.two.commodityorder.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.two.commodityorder.model.Commodity;
import com.two.commodityorder.service.CommodityService;
import com.two.commodityorder.service.impl.CommodityServiceImpl;

@WebServlet("/selectCommodityByIdServlet.do")
public class SelectCommodityByIdServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String id = req.getParameter("id");
		CommodityService service = new CommodityServiceImpl();
		Commodity u = service.selectByCommodityId(id);
		resp.setContentType("application/json");
		PrintWriter pw = resp.getWriter();
		Gson gson = new Gson();		
		String result = gson.toJson(u);
		pw.append(result);
		pw.flush();
		pw.close();	
	}
}